package com.open.capacity.workflow3.service.impl;

import com.open.capacity.reimburse.util.uuid.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.open.capacity.commons.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.open.capacity.commons.CodeEnum;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.collections4.MapUtils;

import com.open.capacity.workflow3.entity.NwfTaskRelation;
import com.open.capacity.workflow3.dao.NwfTaskRelationDao;
import com.open.capacity.workflow3.service.NwfTaskRelationService;


@Service
public class NwfTaskRelationServiceImpl implements NwfTaskRelationService {

    @Autowired
    private NwfTaskRelationDao nwfTaskRelationDao;

    /**
     * 添加
     *
     * @param nwfTaskRelation
     */
    public int save(NwfTaskRelation nwfTaskRelation) {
        nwfTaskRelation.setId(UUIDUtils.getOriginalUUIDWithoutBar());
        nwfTaskRelation.setMark(0);
        nwfTaskRelation.setCreateTime(new Date());
        return nwfTaskRelationDao.save(nwfTaskRelation);
    }

    /**
     * 修改
     *
     * @param nwfTaskRelation
     */
    public int update(NwfTaskRelation nwfTaskRelation) {
        return nwfTaskRelationDao.update(nwfTaskRelation);
    }


    /**
     * 删除
     *
     * @param id
     */
    public int delete(String id) {
        return nwfTaskRelationDao.delete(id);
    }

    /**
     * 查询记录
     *
     * @param id
     * @return
     */
    public NwfTaskRelation findById(String id) {
        return nwfTaskRelationDao.findById(id);
    }

    /**
     * 分页
     *
     * @param params
     * @return
     */
    public PageResult<NwfTaskRelation> pageAll(Map<String, Object> params) {
        //设置分页信息，分别是当前页数和每页显示的总记录数【记住：必须在mapper接口中的方法执行之前设置该分页信息】
        if (MapUtils.getInteger(params, "page") != null && MapUtils.getInteger(params, "limit") != null)
            PageHelper.startPage(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"), true);

        List<NwfTaskRelation> list = nwfTaskRelationDao.findAll(params);
        PageInfo<NwfTaskRelation> pageInfo = new PageInfo(list);

        return PageResult.<NwfTaskRelation>builder().data(pageInfo.getList()).resp_code(CodeEnum.SUCCESS.getCode()).count(pageInfo.getTotal()).build();
    }

    /**
     * 列表
     *
     * @param params
     * @return
     */
    public List<NwfTaskRelation> findAll(Map<String, Object> params) {
        return nwfTaskRelationDao.findAll(params);
    }

}
